package com.hongxun.project.assets.bMaterial.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.bMaterial.domain.BMaterial;
import com.hongxun.project.assets.bMaterial.service.IBMaterialService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 配电材料 信息操作处理
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/bMaterial")
public class BMaterialController extends BaseController
{
    private String prefix = "assets/bMaterial";
	
	@Autowired
	private IBMaterialService bMaterialService;
	
//	@RequiresPermissions("assets:bMaterial:view")
	@GetMapping()
	public String bMaterial()
	{
	    return prefix + "/bMaterial";
	}
	
	/**
	 * 查询配电材料列表
	 */
//	@RequiresPermissions("assets:bMaterial:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BMaterial bMaterial)
	{
		startPage();
        List<BMaterial> list = bMaterialService.selectBMaterialList(bMaterial);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出配电材料列表
	 */
	@RequiresPermissions("assets:bMaterial:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BMaterial bMaterial)
    {
    	List<BMaterial> list = bMaterialService.selectBMaterialList(bMaterial);
        ExcelUtil<BMaterial> util = new ExcelUtil<BMaterial>(BMaterial.class);
        return util.exportExcel(list, "bMaterial");
    }
	
	/**
	 * 新增配电材料
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存配电材料
	 */
	@RequiresPermissions("assets:bMaterial:add")
	@Log(title = "配电材料", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BMaterial bMaterial)
	{		
		return toAjax(bMaterialService.insertBMaterial(bMaterial));
	}

	/**
	 * 修改配电材料
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		BMaterial bMaterial = bMaterialService.selectBMaterialById(id);
		mmap.put("bMaterial", bMaterial);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存配电材料
	 */
	@RequiresPermissions("assets:bMaterial:edit")
	@Log(title = "配电材料", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BMaterial bMaterial)
	{		
		return toAjax(bMaterialService.updateBMaterial(bMaterial));
	}
	
	/**
	 * 删除配电材料
	 */
	@RequiresPermissions("assets:bMaterial:remove")
	@Log(title = "配电材料", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bMaterialService.deleteBMaterialByIds(ids));
	}
	
}
